package com.googlecode.lohr.tools.interpreter;

import java.util.HashMap;
import java.util.Map;

import lohr.lang.dom.IdentifierName;

@SuppressWarnings("unchecked")
public class LohrRepository {
	
	private Map<String, ObjectImpl> _resourcesByURI= new HashMap<String, ObjectImpl>();

	/**
	 * Find an object by it's URI
	 */
	public <T extends ObjectImpl> T findByURI(String uri) {
		return (T) _resourcesByURI.get(uri);
	}

	/**
	 * Register an object in the repository
	 */
	public void register(ObjectImpl obj) {
		_resourcesByURI.put(obj.getURI(), obj);
	}

	/**
	 * Finds an object by IdentifierName.
	 * It is assumed that the given IdentifierName is fully qualified, that is, 
	 * the name is actually a URI.
	 * Any type parameters specified by the given IdentifierName are also used 
	 * to find an appropriate element.  
	 */
	public <T extends ObjectImpl> T findByIdentifier(IdentifierName methodIdentifier) {
		return (T) _resourcesByURI.get(methodIdentifier.getName());
	}

}
